package Year22_Month04.day23;

public class 复习_删除倒数第n个节点 {
    public ListNode removeNthFromEnd(ListNode head, int n) {

        ListNode fast = head;
        ListNode key = new ListNode(0,head);
        ListNode slow = key;
        int count = 0;
        while(count < n){
            fast = fast.next;
            count++;
        }
        while(fast != null){
            slow = slow.next;
            fast = fast.next;
        }
        slow.next = slow.next.next;
        return key.next;
    }
}
